<?php

namespace app\common\model;

use think\Model;

/**
 * Class Vip
 * @package app\common\model
 *
 * @property-read int $id
 * @property int $state
 * @property float $fee
 * @property float $origin_fee
 * @property string $title
 * @property int $time_unit
 * @property int $time_expire
 * @property int $sort
 */
class Vip extends Model
{
    const UNIT_VALUE = ['day', 'month', 'year'];

    /**
     * 计算过期时间
     * @param int|null $originTime
     * @return false|int
     */
    public function getTime($originTime = null)
    {
        $unit = self::UNIT_VALUE[$this->time_unit];
        return date('Y-m-d', strtotime("+{$this->time_expire}{$unit}", $originTime ?: time()));
    }

    /**
     * @param int $id
     * @return array|Model|null|self
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getById($id)
    {
        return self::find($id);
    }
}